package com.dal.manager;

import com.dal.db.bean.Account;
import com.dal.db.cache.AccountCache;
import com.dal.gm_api.constant.OperateAccountType;
import com.dal.gm_api.util.GMError;
import com.google.common.collect.Lists;
import org.bean.InterceptInfoDTO;
import org.error.GMErrorCode;

import java.util.List;
import java.util.Map;

/**
 * Created by fxf on 2018-1-16.
 */
public class AccountManager {

    public static void operateAccount(int type, List<String> uids, Map paramMap) {
        List<Account> accountList = Lists.newArrayList();
        
        uids.forEach(uid -> {
            Account account = AccountCache.me().getById(uid);
            GMError.isAndTrue(GMErrorCode.PARAM_ERR, "玩家账号没有找到", account == null);
            accountList.add(account);
        });
        
        if (type == OperateAccountType.ADMIN) {
            Boolean admin = (Boolean) paramMap.get("admin");
            GMError.isAndTrue(GMErrorCode.PARAM_ERR, "没有找到admin参数", admin == null);
            accountList.forEach(account -> account.setAdmin(admin));
        }
        
        if (accountList.size() >0){
            AccountCache.me().updateBatch(accountList);
        }
    }

//    public static void changeAccountState(List<InterceptInfoDTO> list) {
//        list.forEach(dto->{
//            if (dto.getUid() == null || "".equals(dto.getUid())){
//                return;
//            }
//            Account account = AccountCache.me().getById(dto.getUid());
//            GMError.isAndTrue(GMErrorCode.PARAM_ERR, "玩家账号没有找到", account == null);
//            account.setState(dto.getType());
//            account.update();
//        });
//    }
//
//    public static void remoteAccountState(List<InterceptInfoDTO> list) {
//        list.forEach(dto->{
//            if (dto.getUid() == null || "".equals(dto.getUid())){
//                return;
//            }
//            Account account = AccountCache.me().getById(dto.getUid());
//            GMError.isAndTrue(GMErrorCode.PARAM_ERR, "玩家账号没有找到", account == null);
//            if (account.getState() == dto.getType()){
//                account.setState(0);
//                account.update();
//            }
//        });
//    }
}
